String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, '');
}

Array.prototype.has=function(v) {
	for (var i=0; i<this.length; i++) {
		if (this[i] == v) {
			return i;
		}
	}
	return -1;
}

Array.prototype.compareTo = function(testArr) {
	if (this.length != testArr.length) {
		return false;
	}

	for (var i = 0; i < testArr.length; i++) {
		if (this[i].compare) {
			if (!this[i].compare(testArr[i])) {
				return false;
			}
		}
		if (this[i] !== testArr[i]) {
			return false;
		}
	}
	return true;
}

function showError(message) {
	alert(message);
}

function showMessage(message) {
	alert(message);
}

function selectOption(selector, optValue) {
	if (!optValue)
		return false;

	for (var o=0; o<selector.options.length; o++) {
		if (selector.options[o].value == optValue) {
			selector.options[o].selected = true;
			return o;
		}
	}

	return false;
}


function isEnum(val) {
	if (val.startsWith("(") && val.endsWith(")")) {
		var toReturn = new Array();
		return val.substring(1, val.length-1).split(/\s*,\s*/);
	}

	return null;
}

function compare(obj1, obj2) {
	return (
		( (typeof(obj1) == "object") && (typeof(obj2) == "object") && obj1.compareTo(obj2) )
		||
		(obj1 == obj2) );

}

function enableNodesOfType(root, types, enable, disregardClasses) {
	for (var i=0; i<root.childNodes.length; i++) {
		if (root.childNodes[i].nodeType == 1) {
			for (var j=0; j<types.length; j++) {
				if (root.childNodes[i].nodeName.toLowerCase() == types[j].toLowerCase()) {

					var takeAction = true;
					if (disregardClasses != null) {
						if ( (typeof(disregardClasses) == "object") && (disregardClasses.has(root.childNodes[i].className) != -1)) {
							takeAction = false;
						} else if ( (typeof(disregardClasses) == "string") && (disregardClasses = root.childNodes[i].className) ) {
							takeAction = false;
						}
					}

					if (takeAction) {
						root.childNodes[i].disabled = !enable;
					}
				}
			}
			enableNodesOfType(root.childNodes[i], types, enable, disregardClasses);
		}
	}
}

function removeChildren(elm) {
	while (elm.hasChildNodes()) {
		elm.removeChild(elm.firstChild);
	}
}

function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent) {
		while (1) {
			curleft += obj.offsetLeft;
			if (!obj.offsetParent) {
				break;
			}
			obj = obj.offsetParent;
		}
	} else if(obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (1) {
			curtop += obj.offsetTop;
			if (!obj.offsetParent) {
				break;
			}
			obj = obj.offsetParent;
		}
	} else if(obj.y) {
		curtop += obj.y;
	}
	return curtop;
}